Poetry で PyTorch + Torchvision
追記:Poetry のα版リリースを使うとうまくいきます
Poetry で PyTorch + Torchvision 再々チャレンジ作業ログ(成功)
Poetry で Torchvision をインストールする方法
Poetry で PyTorch を入れる で PyTorch をインストールすると、インストールされるパッケージのバージョンは 1.9.0+cu111になる
(CUDA 11.1 環境に Torch 1.9.0 を入れたら、という話)
同じやりかたで Torchvision の Wheel の URL を指定してインストールしようとすると、この torchvision はtorch==1.9.0+cu111ではなくtorch==1.9.0に依存しているためコンフリクトする
これは本来コンフリクトしてはいけない by PEP
PEP 440 における記載
If the specified version identifier is a public version identifier (no local version label), then the local version label of any candidate versions MUST be ignored when matching versions.
+xxx は local version label といい、PEP 440 で定義されているが、 Poetry はこれを正しく解釈していない?
Issue https://github.com/python-poetry/poetry/issues/2543
the package torchvision (0.5.0+cpu) depends on torch (1.4.0). However, I've specified that I need torch (1.4.0+cpu). The PEP says that the local identifier MUST be ignored when performing the version match for the constraint coming from the torchvision (0.5.0+cpu) package. So I would say that this conflict is actually an acceptable solution, given the constraints.
わからん!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
これ Poetry が悪くないか?
→ 修正されてた https://github.com/python-poetry/poetry/pull/3831
1.2.0a1 から有効になるらしい
1.1.x はバグフィクスだけだから 1.2.0 のプレビュー版に入れるって何!?!?仕様の解釈ミスは明らかにバグだろ!!
poetry self update --previewではなぜか失敗する上に~/.poetryが破壊されてすべてが終了するので Pip でインストールしなおした
pip3 install --user --pre poetry
こんなに昔から指摘されてたのに… https://github.com/python-poetry/poetry/issues/892
結果
code:pyproject.toml
tool.poetry.dependencies
python = "^3.8"
torch = {url = "https://download.pytorch.org/whl/cu111/torch-1.9.0%2Bcu111-cp38-cp38-linux_x86_64.whl"}
torchvision = {url = "https://download.pytorch.org/whl/cu111/torchvision-0.10.0%2Bcu111-cp38-cp38-linux_x86_64.whl"}
こう書いて Poetry 1.2.0a2 でpoetry installするとうまくいく^^